03. Reading ToDo items: The “R” in CRUD

Reading todo items: The “R” in CRUD Heading

Implementing Reads: The “R” in CRUD

We'll demonstrate how to implement read operations: querying the database to return data-backed views, replacing our dummy data with "real" data coming from our database.

ND004 C01 L05 03 Reading Todo Items- The “R” In CRUD

Reading todo items: The “R” in CRUD Recap

Follow along in the workspace below

Starter Code you can use

This code comes from following along the previous screencast and lets you start following along on this current screencast. You can use this as starter code if you'd like to reset your workspace code to a working state.

Solution code to this screencast are provided when you go to the next section.

todoapp/app.py
from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def index():
  return render_template('index.html', data=[{
    'description': 'Todo 1'
  }, {
    'description': 'Todo 2'
  }, {
    'description': 'Todo 3'
  }])
todoapp/templates/index.html
<html>
  <head>
    <title>Todo App</title>
  </head>
  <body>
    <ul>
      {% for d in data %}
      <li>{{ d.description }}</li>
      {% endfor %}
    </ul>
  </body>
</html>

Reset your database anytime

If ever you corrupt your data schema or need to reset your database, remember you can do that in your terminal by using

dropdb todoapp && createdb todoapp

Workspace

This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity , so you may be able to download them there.

Workspace Information:

  • Default file path:
  • Workspace type: jupyter-lab
  • Opened files (when workspace is loaded): n/a